package com.pphh.demo.metric;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;

import java.util.Queue;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedDeque;

/**
 * Please add description here.
 *
 * @author huangyinhuang
 * @date 11/6/2018
 */
public class QueueManager {

    private final Queue queue;

    public QueueManager(MetricRegistry metrics, String name) {
        this.queue = new ConcurrentLinkedDeque();
        metrics.register(MetricRegistry.name(QueueManager.class, name, "size"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        return queue.size();
                    }
                });
    }

    public void enque() {
        this.queue.add(new Random().nextInt(100));
    }

    public void deque() {
        this.queue.remove();
    }

}
